A Better Way To Extract Date From DateTime Columns [SQL Server]

Posted by Gopinath on Tech Dreams See other posts from Tech Dreams or by Gopinath
Published on Wed, 09 Mar 2011 02:30:00 +0000 Indexed on 2011/03/09 8:17 UTC
Read the original article Hit count: 235

Filed under:
|
|


Quite a long ago I wrote about a SQL Server programming tip on how to extract date part from a DATETIME column. The post discusses about using of T SQL function convert() to get date part. One of the readers of the post, tipped me about a better way of extracting date part and here is the SQL query he sent to us

SELECT DateAdd(day, DateDiff(day, 0, getdate()), 0);

In clean way this query trims off time part from the DATETIME value. I rate this solution better than the one I wrote long ago as this one does not depend on any string operations. According the commenter, this method is faster compared to the other. What do you say?

Thanks Yamo

This article titled,A Better Way To Extract Date From DateTime Columns [SQL Server], was originally published at Tech Dreams. Grab our rss feed or fan us on Facebook to get updates from us.

© Tech Dreams or respective owner

Related posts about Microsoft

Related posts about SQL Server